//
//  ViewController.swift
//  C007_test_UIBezierPath
//
//  Created by yao_yu on 15/5/28.
//  Copyright (c) 2015年 yao_yu. All rights reserved.
//

import UIKit

class MyView: UIView {
    override func drawRect(rect: CGRect) {
        let color = UIColor.redColor()
        color.set()
        
        let aPath = UIBezierPath()
        aPath.lineWidth = 1.0
        
        aPath.lineCapStyle = kCGLineCapRound
        aPath.lineJoinStyle = kCGLineJoinBevel
        
        aPath.moveToPoint(CGPointMake(100.0, 0.0))
        aPath.addLineToPoint(CGPointMake(200.0, 40.0))
        aPath.addLineToPoint(CGPointMake(160, 140))
        aPath.addLineToPoint(CGPointMake(40.0, 140))
        aPath.addLineToPoint(CGPointMake(0.0, 40.0))
        aPath.closePath()   //第五条线通过调用closePath方法得到的
        aPath.fill()

        aPath.stroke() //Draws line 根据坐标点连线
        
        

    }
}


class ViewController: UIViewController {

    var myView = MyView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        myView.backgroundColor = UIColor.whiteColor()
        view.addSubview(myView)
    }

    override func viewDidLayoutSubviews() {
        myView.frame = CGRectMake(0, 20, view.frame.width, view.frame.height - 20)
    }

    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

